//
// Redux库便捷函数
//

/**
 * 创建 redux action
 * @param  {String} type 动作类型
 * @param  {Mixed} data 传递数据
 * @return {Object}
 */
export const createAction = (type, ...data) => {
  return (...args) => {
    let action = { type };
    data.forEach((arg, i) => {
      action[data[i]] = args[i];
    });
    return action;
  };
};


export const createReducer = (initState, handlers) => {
  return (state=initState, action) => {
    if(handlers.hasOwnProperty(action.type)){
      return handlers[action.type](state, action);
    }
    else{
      return state;
    }
  };
};
